// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class randomData {

    private static updateTimes = 6;

    private static lastSkinList = [];

    private static lastUpdateTimes = -1;

    private static startUseRandomSkinTimes = -1;

    private static startUseRandomSkinMaxTimes = 15;

    private static isStartUseSkin = false;

    public static getRoleUsingTimes(){
        return this.startUseRandomSkinMaxTimes;
    }

    public static resetRoleUsingTimes(){
        this.startUseRandomSkinTimes = new Date().getTime();
    }

    public static getSkinList(){
        if(this.lastUpdateTimes == -1){
            this.lastUpdateTimes = new Date().getTime();
        }
        return this.lastSkinList;
    }

    public static setSkinList(list){
        this.lastSkinList = list;
    }

    public static getStartUseSkin(){
        return this.isStartUseSkin;
    }

    public static setStartUseSkin(use){
        if(!this.isStartUseSkin){
            this.lastUpdateTimes = new Date().getTime();
            this.startUseRandomSkinTimes = new Date().getTime();
            this.isStartUseSkin = use;
        }
    }

    public static backCountTimes(){
        if(!this.isStartUseSkin) return null;
        let date = new Date().getTime();
        let delDate = date - this.startUseRandomSkinTimes;
        let min = Math.floor((delDate / (1000 * 60)) % 60);
        let sed = Math.floor(delDate % (1000 * 60) / 1000);
        return [min,sed];
    }

    public static isUpdate(){
        if(!this.isStartUseSkin) return;
        let date = new Date().getTime();
        let delDate = date - this.lastUpdateTimes;
        let min = Math.floor((delDate / (1000 * 60)) % 60);
        let sed = Math.floor(delDate % (1000 * 60) / 1000) ;
        console.log(min,sed);
        if(min >= this.updateTimes){
            this.lastUpdateTimes = date;
            return true;
        }else{
            return false;
        }
    }

    public static setTimes(time){
        this.lastUpdateTimes = time;
    }

    public static isUseRandomSkin(){

        let date = new Date().getTime();
        let delDate = date - this.startUseRandomSkinTimes;
        let min = Math.floor((delDate / (1000 * 60)) % 60);
    
        if(min >= this.startUseRandomSkinMaxTimes){
            return false;
        }else{
            return true;
        }
    }

    public static setUseRandomSkinTimes(){
        this.startUseRandomSkinTimes = new Date().getTime();
    }
}
